<?php
namespace app\filters;

use yii\base\ActionFilter;
class ResponseFilter extends ActionFilter {
	const STATUS_ERROR_PARAM = 1;
	const STATUS_ERROR_LOGIC = 2;
	
	public function afterAction($action, $result) {
		if (is_array($result) && !isset($result['status'])) {
			if (isset($result['errors'])) {
				$result['status'] = self::STATUS_ERROR_PARAM;
			} else if (isset($result['error'])) {
				$result['status'] = self::STATUS_ERROR_LOGIC;
			} else {
				$result['status'] = 0; 
			}
		}
		return $result;
	}
}